#!/usr/bin/env node
const program = require('commander');

// -V 大写的命令是 commander 的
//设置 -V 命令的返回值，默认是 大写的 -V，可以改成 -v、--version
// program.parse(process.argv);
//定义挂在主命令上的选项
program.option('-d, --debug', 'output extra debugging')
.option('-s, --small', 'small pizza size')
.option('-p, --pizza-type <type>', 'flavour of pizza', 'test')
.option('--no-sauce', 'remove asuce')
// .option('--cheese [flavour]' ,'cheese flavour', 'mozzarella')
.option('--no-cheese', 'plain with no cheese')
.requiredOption('-c, --cheese <type>', 'pizza must have cheese')
.option('-l, --letter <letters...>', 'specify letters')
.parse();

program.version('0.0.1', '-v, --version').parse(process.argv);
program.command('add <num> [otherDirs...]', 'initial description').option('-n, --name <items1> [items2]', 'name description', 'default value', {
    noHelp: false
    // isDefault: true
});

program.command('serve [others...]', 'start server')
    .option('-p, --port <items1> [items2]', 'network port', 7001)
    .option('-e, --env <items1> [items2]', 'process env NODE_ENV', 'wechat')
    .action(function (a, b, c) {
        console.log(a);
        console.log(b);
        console.log(c);
    });

// program.alias('r').usage('[options] <file...>').description('run setup commands for all envs');

program
    .command('rm <dest> [otherDirs...]')
    .alias('r')
    .option('-r, --recursive', 'Remove recursively')
    .option('-d --drink [drink]', 'Drink', 'Beer')
    .action(function (d, otherD, cmd) {
        console.log('remove ' + d, (cmd.drink), (cmd.recursive))
        if (otherD) {
            otherD.forEach(function (oDir) {
                console.log('rmdir %s', oDir);
            });
        }

    })

// program.parse(process.argv);

//所有配置
const options = program.opts();
console.log(options);
if (options.debug) {
    console.log('debug is true');
}

if (options.small) {
    console.log('smaller the pizza');
}

if (options.pizzaType) {
    console.log(`-${options.pizzaType}`);
}

if(options.letter){
    console.log(`Remaining arguments:`, options.letter);
}

let sauceStr = options.sauce?'sauce':'no sauce';
let cheeseStr = (options.cheese===false)?'no cheese': `${options.cheese} cheese`;
console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
// console.log(program.args);
